/*Play sound component*/
/*
 * profile:    JSON, {src:'chimes.wav',altSrc:'',loop:false}
 * 
 * setSrc:     Function, set the source of sound
 * play:       Function, play sound
 */
if (!Util){
    var Util = {};
}
Util.soundComponent=function(profile){
	this.profile={
        src:'',
        altSrc:'',
        loop:false
    };
    if(profile) {
        $.extend(this.profile,profile);
    }
    this.soundObj=null;
    this.isIE = !-[1,];
    this.init();
};
Util.soundComponent.prototype={
    init:function(){
        this._setSrc();
    },        
    _setSrc:function(){
        if(this.soundObj){
            if(this.isIE){
                this.soundObj[0].src=this.profile.src;
            }else{
                this.soundObj[0].innerHTML='<source src="'+this.profile.src+'" /><source src="'+this.profile.altSrc+'" />';    
            }
        }else{
            if(this.isIE){
                this.soundObj=$('<bgsound volume="-10000" loop="1" src="'+this.profile.src+'">').appendTo('body');
            }else{
                this.soundObj=$('<audio preload="auto" autobuffer><source src="'+this.profile.src+'" /><source src="'+this.profile.altSrc+'" /></audio>').appendTo('body');
            }
        }
    },
    setSrc:function(src,altSrc){
        this.profile.src=src;
        if(typeof altSrc!='undefined'){
            this.profile.altSrc=altSrc;
        }
		this._setSrc();
    },
    play:function(){
        if(this.soundObj){
            if(this.isIE){
                this.soundObj[0].volume = 1;
                this.soundObj[0].src = this.profile.src;
            }else{
                this.soundObj[0].play();
            }
        }
    }
};